package com.jlkf.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jlkf.dao.BackCourseInfoDao;
import com.jlkf.pojo.TblCourse;
import com.jlkf.pojo.TblLesson;
import com.jlkf.service.BackCourseInfoService;
import com.jlkf.service.VideoService;
import com.platform.server.response.response.pojo.ReturnData;
import com.platform.server.util.StringTools;
import com.platform.server.util.excel.ExcelUtil;

@Controller
@RequestMapping("/courseInfo")
public class BackCourseInfoController {
	
	@Autowired
	private BackCourseInfoService backCourseInfoService;
	
	@Autowired
	private BackCourseInfoDao backCourseInfoDao;
	
	@Autowired
	private VideoService videoService;
	
	/**
	 * 查看课程列表
	 */
	@ResponseBody
	@RequestMapping("/selectCourseInfoList")
	public Object selectCourseInfoList(String startTime,String endTime,String courseName,Integer id,String type,Integer pageNumber,Integer pageSize){
		Map<String, Object> map = new HashMap<String,Object>();
		if(!StringTools.isEmpty(startTime)){
			map.put("startTime", startTime);
		}
		if(!StringTools.isEmpty(endTime)){
			map.put("endTime", endTime);
		}
		if(!StringTools.isEmpty(courseName)){
			map.put("courseName", courseName);
		}
		if(id != null){
			map.put("id", id);
			ModelAndView modelAndView = new ModelAndView();
			if("1".equals(type)){
				modelAndView.setViewName("jsp/courseInfoManager/courseDetail");
			}else if("2".equals(type)){
				modelAndView.setViewName("jsp/courseInfoManager/courseDetailUpdate");
			}
			List<Map<String, Object>> lists = backCourseInfoService.selectCourseInfoList(map);
			modelAndView.addObject("result", lists.get(0));
			return modelAndView;
		}
		if(pageNumber == null && pageSize == null){
			List<Map<String, Object>> lists = backCourseInfoService.selectCourseInfoList(map);
			return new ReturnData(lists,200,"课程列表");
		}
		PageHelper.startPage(pageNumber, pageSize);
		List<Map<String, Object>> lists = backCourseInfoService.selectCourseInfoList(map);
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(lists);
		return new ReturnData(lists,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"课程列表");
	}
	
	/**
	 * 查看课时列表
	 */
	@ResponseBody
	@RequestMapping("/selectLessonList")
	public Object selectLessonList(Integer id,String lessonid,Integer pageNumber,Integer pageSize){
		String lessons = backCourseInfoDao.selectRelatedlesson(id);
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("lessons", lessons);
		PageHelper.startPage(pageNumber, pageSize);
		List<Map<String, Object>> lists = backCourseInfoService.selectLessonList(map);
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(lists);
		return new ReturnData(lists,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"课时列表");
	}
	
	/**
	 * 删除课时
	 */
	@ResponseBody
	@RequestMapping("/deleteLesson")
	public Object deleteLesson(String lessonid,Integer courseid){
		String lessons = backCourseInfoDao.selectRelatedlesson(courseid);
		if(lessons.contains(lessonid + ",")){
			lessons = lessons.replace(lessonid + ",", "");
		}
		if(lessons.contains("," + lessonid)){
			lessons = lessons.replace("," + lessonid, "");
		}
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("lessons", lessons);
		map.put("courseid", courseid);
		int flag = backCourseInfoService.deleteLesson(map);
		//课时详情
		Map<String,Object> hashMap = new HashMap<String,Object>();
		hashMap.put("id", Integer.parseInt(lessonid));
		List<Map<String, Object>> lists = videoService.selectVideoList(hashMap);
		Double money = (Double)lists.get(0).get("G_LESSON_MONEY");
		Integer integeal = (Integer)lists.get(0).get("G_LESSON_INTEGEAL");
		//修改课程信息
		Map<String,Object> hm = new HashMap<String,Object>();
		hm.put("money", money);
		hm.put("integeal", integeal);
		hm.put("courseid", courseid);
		backCourseInfoDao.updateCourseInfo(hm);
		Map<String,Object> hmap = new HashMap<String,Object>();
		hmap.put("courseid", courseid);
		List<Map<String, Object>> courseInfo = backCourseInfoService.selectCourseInfoList(hmap);
		Double courseMoney = (Double)courseInfo.get(0).get("G_COURSE_MONEY");
		if(courseMoney == 0){
			Map<String,Object> map2 = new HashMap<>();
			map2.put("G_ID",courseid);
			map2.put("G_IS_FEE", 2);
			backCourseInfoService.updateCourse(map2);
		}
		if(flag > 0){
			return new ReturnData(200,"删除成功");
		}else{
			return new ReturnData(500,"删除失败");
		}
	}
	
	/**
	 * 删除课程
	 */
	@ResponseBody
	@RequestMapping("/deleteCourse")
	public Object deleteCourse(String id){
		int flag = backCourseInfoService.deleteCourse(id);
		if(flag > 0){
			return new ReturnData(200,"删除成功");
		}else{
			return new ReturnData(500,"删除失败");
		}
	}
	
	/**
	 * 根据关键字查看视频列表
	 */
	@ResponseBody
	@RequestMapping("/selectVideoList")
	public Object selectVideoList(String videoName,Integer G_IS_FEE,Integer G_COURSE_INTEGEAL){
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("videoName", videoName);
		//map.put("G_IS_FEE", G_IS_FEE);
		
		
		
		//map.put("G_COURSE_INTEGEAL", G_COURSE_INTEGEAL);
		List<Map<String,Object>> lists = backCourseInfoService.selectVideoList(map);
		return new ReturnData(lists,200,"视频列表");
	}
	
	/**
	 * 添加课程
	 */
	@ResponseBody
	@RequestMapping("/insertCourse")
	public Object insertCourse(Integer G_IS_FEE,String G_COURSE_IMG,String G_COURSE_NAME,Integer G_COURSE_DIFFICUITY,Integer G_LEAM_NUM,
			String G_COUESR_CONTENT,Integer G_DISCOUNT,String G_COURSE_AIMS,String awesompletedTpl,Integer one_stair_id,Integer two_stair_id,
			Integer G_COUSER_SORT_ID,Integer is_agency){
		String[] split = awesompletedTpl.split(",");
		String G_RELATED_COURSE = "";
		Double G_COURSE_MONEY = 0D;
		Integer G_COURSE_INTEGEAL = 0;
		Integer G_COURSE_TOTAL_DURATION = 0;
		Boolean fl = false;
		for(int i =0;i < split.length;i++){
			Map<String, Object> map = backCourseInfoDao.selectVideoInfo(split[i]);
			if(map == null){
				return new ReturnData(300,"请输入正确的视频名称！");
			}
			if((Integer)map.get("G_LESSON_INTEGEAL") == 0 && (Integer)map.get("G_LESSON_IS_FEE") == 1){
				fl = true;
			}
			G_RELATED_COURSE += map.get("G_ID") + ",";
			G_COURSE_MONEY += (Double)map.get("G_LESSON_MONEY");
			G_COURSE_INTEGEAL += (Integer)map.get("G_LESSON_INTEGEAL");
			G_COURSE_TOTAL_DURATION += Integer.parseInt(map.get("G_LESSON_DURATION").toString());
		}
		Map<String,Object> map = new HashMap<>();
		if(G_COURSE_MONEY > 0){
			map.put("G_IS_FEE", 1);
		}else{
			map.put("G_IS_FEE", 2);
		}
		if(fl){
			map.put("G_COURSE_INTEGEAL", 0);
		}else{
			map.put("G_COURSE_INTEGEAL", G_COURSE_INTEGEAL);
		}
		map.put("is_agency", is_agency);
		map.put("one_stair_id", one_stair_id);
		map.put("two_stair_id", two_stair_id);
		map.put("G_COUSER_SORT_ID", G_COUSER_SORT_ID);
		map.put("G_COURSE_IMG", G_COURSE_IMG);
		map.put("G_COURSE_NAME", G_COURSE_NAME);
		map.put("G_COURSE_DIFFICUITY", G_COURSE_DIFFICUITY);
		map.put("G_LEAM_NUM", G_LEAM_NUM);
		map.put("G_COURSE_MONEY", G_COURSE_MONEY);
		map.put("G_COURSE_TOTAL_DURATION", G_COURSE_TOTAL_DURATION / 60);
		map.put("G_DISCOUNT", G_DISCOUNT);
		map.put("G_COURSE_AIMS", G_COURSE_AIMS);
		map.put("G_COUESR_CONTENT", G_COUESR_CONTENT);
		map.put("G_LESSON_NUM", split.length);
		map.put("G_RELATED_COURSE", G_RELATED_COURSE.substring(0, G_RELATED_COURSE.length() - 1));
		int flag =  backCourseInfoService.insertCourse(map);
		if(flag > 0){
			return new ReturnData(200,"添加成功");
		}else{
			return new ReturnData(500,"添加失败");
		}
	}
	
	/**
	 * 编辑课程
	 */
	@ResponseBody
	@RequestMapping("/updateCourse")
	public Object updateCourse(Integer G_IS_FEE,String G_COURSE_IMG,String G_COURSE_NAME,Integer G_COURSE_DIFFICUITY,Integer G_LEAM_NUM,
			String G_COUESR_CONTENT,Integer G_DISCOUNT,String G_COURSE_AIMS,String awesompletedTpl,Integer one_stair_id,Integer two_stair_id,
			Integer G_COUSER_SORT_ID,Integer is_agency,Integer G_ID){
		Map<String,Object> map = new HashMap<>();
		if(!StringTools.isEmpty(awesompletedTpl)){
			String G_RELATED_COURSE = "";
			Double G_COURSE_MONEY = 0D;
			Integer G_COURSE_INTEGEAL = 0;
			Integer G_COURSE_TOTAL_DURATION = 0;
			String[] split = awesompletedTpl.split(",");
			Boolean fl = false;
			for(int i =0;i < split.length;i++){
				Map<String, Object> map2 = backCourseInfoDao.selectVideoInfo(split[i]);
				if(map2 == null){
					return new ReturnData(300,"请输入正确的视频名称！");
				}
				if((Integer)map2.get("G_LESSON_INTEGEAL") == 0 && (Integer)map2.get("G_LESSON_IS_FEE") == 1){
					fl = true;
				}
				G_RELATED_COURSE += map2.get("G_ID") + ",";
				G_COURSE_MONEY += (Double)map2.get("G_LESSON_MONEY");
				G_COURSE_INTEGEAL += (Integer)map2.get("G_LESSON_INTEGEAL");
				G_COURSE_TOTAL_DURATION += Integer.parseInt(map2.get("G_LESSON_DURATION").toString());
			}
			if(G_COURSE_MONEY > 0){
				map.put("G_IS_FEE", 1);
			}else{
				map.put("G_IS_FEE", 2);
			}
			if(fl){
				map.put("G_COURSE_INTEGEAL", 0);
			}else{
				map.put("G_COURSE_INTEGEAL", G_COURSE_INTEGEAL);
			}
			map.put("G_COURSE_TOTAL_DURATION", G_COURSE_TOTAL_DURATION / 60);
			map.put("G_LESSON_NUM", split.length);
			map.put("G_RELATED_COURSE", G_RELATED_COURSE.substring(0, G_RELATED_COURSE.length() - 1));
			map.put("G_COURSE_MONEY", G_COURSE_MONEY);
		}
		map.put("G_ID", G_ID);
		map.put("is_agency", is_agency);
		map.put("one_stair_id", one_stair_id);
		map.put("two_stair_id", two_stair_id);
		map.put("G_COUSER_SORT_ID", G_COUSER_SORT_ID);
		map.put("G_COURSE_IMG", G_COURSE_IMG);
		map.put("G_COURSE_NAME", G_COURSE_NAME);
		map.put("G_COURSE_DIFFICUITY", G_COURSE_DIFFICUITY);
		map.put("G_LEAM_NUM", G_LEAM_NUM);
		map.put("G_DISCOUNT", G_DISCOUNT);
		map.put("G_COURSE_AIMS", G_COURSE_AIMS);
		map.put("G_COUESR_CONTENT", G_COUESR_CONTENT);
		int flag =  backCourseInfoService.updateCourse(map);
		if(flag > 0){
			return new ReturnData(200,"编辑成功");
		}else{
			return new ReturnData(300,"编辑失败");
		}
	}
	
	/**
	 * 查看老师列表
	 */
	@ResponseBody
	@RequestMapping("/selectTeacherList")
	public Object selectTeacherList(String G_NAME,Integer id,Integer pageNumber,Integer pageSize){
		if(pageNumber == null || pageSize == null){
			pageNumber = 1;pageSize = 100000;
		}
		Map<String, Object> map = new HashMap<String,Object>();
		
		if(!StringTools.isEmpty(G_NAME)){
			map.put("G_NAME", G_NAME);
		}
		if(id != null){
			map.put("G_ID", id);
			ModelAndView modelAndView = new ModelAndView();
			modelAndView.setViewName("jsp/teacherManager/updateTeacher");
			List<Map<String, Object>> lists = backCourseInfoService.selectTeacherList(map);
			modelAndView.addObject("result", lists.get(0));
			return modelAndView;
		}
		PageHelper.startPage(pageNumber, pageSize);
		List<Map<String, Object>> lists = backCourseInfoService.selectTeacherList(map);
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(lists);
		return new ReturnData(lists,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"老师列表");
	}
	
	/**
	 * 删除老师
	 */
	@ResponseBody
	@RequestMapping("/deleteTeacher")
	public Object deleteTeacher(String id){
		int flag = backCourseInfoService.deleteTeacher(id);
		if(flag > 0){
			return new ReturnData(200,"删除成功");
		}else{
			return new ReturnData(500,"删除失败");
		}
	}
	
	/**
	 * 添加老师
	 */
	@ResponseBody
	@RequestMapping("/insertTeacher")
	public Object insertTeacher(String G_NAME,String G_CONTENT,String G_IMG,String G_SPECIA){
		Map<String,Object> map = new HashMap<>();
		map.put("G_NAME", G_NAME);
		map.put("G_CONTENT", G_CONTENT);
		map.put("G_IMG", G_IMG);
		map.put("G_SPECIA", G_SPECIA);
		int flag =  backCourseInfoService.insertTeacher(map);
		if(flag > 0){
			return new ReturnData(200,"添加成功");
		}else{
			return new ReturnData(500,"添加失败");
		}
	}
	
	/**
	 * 修改老师
	 */
	@ResponseBody
	@RequestMapping("/updateTeacher")
	public Object updateTeacher(String G_ID,String G_NAME,String G_CONTENT,String G_IMG,String G_SPECIA){
		Map<String,Object> map = new HashMap<>();
		map.put("G_ID", Integer.parseInt(G_ID));
		map.put("G_NAME", G_NAME);
		map.put("G_CONTENT", G_CONTENT);
		map.put("G_IMG", G_IMG);
		map.put("G_SPECIA", G_SPECIA);
		int flag =  backCourseInfoService.updateTeacher(map);
		if(flag > 0){
			return new ReturnData(200,"修改成功");
		}else{
			return new ReturnData(500,"修改失败");
		}
	}
	
	/**
	 * 查看职业方向列表
	 */
	@ResponseBody
	@RequestMapping("/selectTprofessionSort")
	public Object selectTprofessionSort(HttpServletRequest request){
		List<Map<String, Object>> lists = backCourseInfoService.selectTprofessionSort();
		return new ReturnData(lists,200,"老师列表");
	}
	
	/**
	 * 查看课程一级二级跟三级分类
	 */
	@ResponseBody
	@RequestMapping("/selectCourseOneStair")
	public Object selectCourseOneStair(Integer sid){
		List<Map<String,Object>> lists = backCourseInfoService.selectCourseOneStair(sid);
		return new ReturnData(lists,200,"分类列表");
	}
	
	/**
	 * 热搜列表
	 */
	@ResponseBody
	@RequestMapping("/hotList")
	public Object hotList(){
		List<Map<String, Object>> lists = backCourseInfoService.hotList();
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(lists);
		return new ReturnData(lists,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"热搜列表");
	}
	
	/**
	 * 删除热搜
	 */
	@ResponseBody
	@RequestMapping("/deleteHot")
	public Object deleteHot(String id){
		int flag = backCourseInfoService.deleteHot(id);
		if(flag > 0){
			return new ReturnData(200,"删除成功");
		}else{
			return new ReturnData(500,"删除失败");
		}
	}
	
	/**
	 * 添加热搜
	 */
	@ResponseBody
	@RequestMapping("/insertHot")
	public Object insertHot(String G_KEYWORDS){
		int flag =  backCourseInfoService.insertHot(G_KEYWORDS);
		if(flag > 0){
			return new ReturnData(200,"添加成功");
		}else{
			return new ReturnData(500,"添加失败");
		}
	}
	
	/**
	 * pc端下拉课程列表
	 */
	@ResponseBody
	@RequestMapping("/dropdownList")
	public Object dropdownList(Integer id,String courseName,Integer pageNumber,Integer pageSize){
		Map<String,Object> map = new HashMap<String,Object>();
		if(!StringTools.isEmpty(courseName)){
			map.put("courseName", courseName);
		}
		if(id != null){
			map.put("id", id);
			List<Map<String, Object>> lists = backCourseInfoService.dropdownList(map);
			ModelAndView modelAndView = new ModelAndView();
			modelAndView.setViewName("jsp/courseInfoManager/addDropdown");
			modelAndView.addObject("course", lists.get(0));
			return modelAndView;
		}
		PageHelper.startPage(pageNumber, pageSize);
		List<Map<String, Object>> lists = backCourseInfoService.dropdownList(map);
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(lists);
		return new ReturnData(lists,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"课程下拉列表");
	}
	
	/**
	 * 删除pc端下拉课程列表
	 */
	@ResponseBody
	@RequestMapping("/deleteDropdown")
	public Object deleteDropdown(String id){
		int flag = backCourseInfoDao.deleteDropdown(id);
		if(flag > 0){
			return new ReturnData(200,"删除成功");
		}else{
			return new ReturnData(500,"删除失败");
		}
	}
	
	/**
	 * 新增或编辑pc端下拉课程列表
	 * @param json
	 * @return
	 */
	@ResponseBody
	@RequestMapping("addOrUpdateDropdown")
	public ReturnData addOrUpdate(@RequestBody Map<String,Object> map){
		if(map.get("id") != null && map.get("id") != ""){
			int ret = backCourseInfoDao.updateDropdown(map);
			if(ret>0){
				return new ReturnData(200,"修改成功");
			}else{
				return new ReturnData(500,"修改失败");
			}
		}else{
			int ret = backCourseInfoDao.insertDropdown(map);
			if(ret>0){
				return new ReturnData(200,"添加成功");
			}else{
				return new ReturnData(500,"添加失败");
			}
		}
	}
	
	/**
	 * 导入课程
	 */
	@ResponseBody
    @RequestMapping("/readExcelCourse") 
    public Object readExcelCourse(@RequestParam(value="excelFile") MultipartFile file,HttpServletRequest request) throws Exception{  
		ModelAndView ModelAndView = new ModelAndView();
		List<TblCourse> newlist = new ArrayList<>();
		try {
	        //判断文件是否为空         
	        String name = file.getOriginalFilename();  
	        long size = file.getSize();  
	        if(name == null || ExcelUtil.EMPTY.equals(name) && size==0){  
	          ReturnData  ReturnData =  new ReturnData("文件为空"); 
	        }  
	        //读取Excel数据到List中  
	        List<ArrayList<String>> list = new excelController().readExcel(file);  
	        if(list == null) {
	        	//ReturnData ReturnData = new ReturnData(200,"成功导入" + newlist.size() + "条数据");
	            //ModelAndView.addObject("ReturnData", ReturnData);
	            request.setAttribute("nums", newlist.size() + "");
	            ModelAndView.setViewName("jsp/courseInfoManager/courseInfoList");
	            return ModelAndView;
	        }
	        for (int i = 0; i < list.size(); i++) {
	    	   ArrayList<String> arrayList = list.get(i);
	    	   TblCourse record = new TblCourse();
		       record.setgCourseName(arrayList.get(0));
		       if("基础".equals(arrayList.get(1))){
		    	   record.setgCourseDifficuity(4);
		       }else if("初级".equals(arrayList.get(1))){
		    	   record.setgCourseDifficuity(1);
		       }else if("中级".equals(arrayList.get(1))){
		    	   record.setgCourseDifficuity(2);
		       }else if("高级".equals(arrayList.get(1))){
		    	   record.setgCourseDifficuity(3);
		       }
		       record.setgLeamNum(Integer.parseInt(arrayList.get(2)));
		       record.setgCourseAims(arrayList.get(3));
		       record.setgDiscount(Double.parseDouble(arrayList.get(4)));
		       if("是".equals(arrayList.get(5))){
		    	   record.setIsAgency(1);
		       }else{
		    	   record.setIsAgency(2);
		       }
		       if("是".equals(arrayList.get(6))){
		    	   record.setIsNew(1);
		       }else{
		    	   record.setIsNew(2);
		       }
		       Map<String,Object> map3 = new HashMap<>();
		       map3.put("G_NAME", arrayList.get(9));
		       map3.put("G_RANK", 3);
		       Map<String, Object> sortInfo3 = backCourseInfoDao.selectSortInfo(map3);
		       Map<String,Object> map2 = new HashMap<>();
		       map2.put("G_NAME", arrayList.get(8));
		       map2.put("G_RANK", 2);
		       Map<String, Object> sortInfo2 = backCourseInfoDao.selectSortInfo(map2);
		       if(sortInfo2.get("G_ID").equals(sortInfo3.get("G_SUPER"))){
		    	   Map<String,Object> map1 = new HashMap<>();
			       map1.put("G_NAME", arrayList.get(7));
			       map1.put("G_RANK", 1);
			       Map<String, Object> sortInfo1 = backCourseInfoDao.selectSortInfo(map1);
			       if(sortInfo1.get("G_ID").equals(sortInfo2.get("G_SUPER"))){
			    	   record.setgCouserSortId((int)Long.parseLong(sortInfo3.get("G_ID").toString()));
			    	   record.setTwo_stair_id((int)Long.parseLong(sortInfo2.get("G_ID").toString()));
			    	   record.setOne_stair_id((int)Long.parseLong(sortInfo1.get("G_ID").toString()));
			       }
		       }
		       
		       String[] split = arrayList.get(10).split(",");
		       String videoId = "";
		       Double G_COURSE_MONEY = 0D;
		       Integer G_COURSE_INTEGEAL = 0,G_COURSE_TOTAL_DURATION = 0;
		       for(int j = 0;j < split.length;j++){
		    	   //根据视频名称查询视频信息
		    	   Map<String, Object> videoInfo = backCourseInfoDao.selectVideoDetails(split[j]);
		    	   Long G_ID = (Long) videoInfo.get("G_ID");
		    	   videoId += G_ID + ",";
		    	   G_COURSE_MONEY += (Double)videoInfo.get("G_LESSON_MONEY");
		    	   G_COURSE_INTEGEAL += (Integer)videoInfo.get("G_LESSON_INTEGEAL");
		    	   G_COURSE_TOTAL_DURATION += (Integer.parseInt(videoInfo.get("G_LESSON_DURATION").toString())) / 60;
		       }
		       record.setgRelatedCourse(videoId.substring(0, videoId.length() - 1));
		       record.setgLessonNum(split.length);
		       record.setgCourseMoney(G_COURSE_MONEY);
		       record.setgCourseIntegeal(G_COURSE_INTEGEAL);
		       record.setgCourseTotalDuration(G_COURSE_TOTAL_DURATION);
		       if(G_COURSE_MONEY > 0){
		    	   record.setgIsFee(1);
		       }else{
		    	   record.setgIsFee(2);
		       }
		       ReturnData insert = backCourseInfoService.readExcelCourse(record);
	           if(insert.getCode() == 200) {
	               newlist.add(record);
	           }
	       }
	       //ReturnData ReturnData = new ReturnData(200,"成功导入"+newlist.size()+"条数据");
	       //ModelAndView.addObject("ReturnData", ReturnData);
	       request.setAttribute("nums", newlist.size() + "");
	       ModelAndView.setViewName("jsp/courseInfoManager/courseInfoList");
	       return ModelAndView;  
		} catch (Exception e) {
			ReturnData ReturnData = new ReturnData(200,"成功导入" + newlist.size() + "条数据");
            ModelAndView.addObject("ReturnData", ReturnData);
            ModelAndView.setViewName("jsp/videoManager/courseInfoList");
            return ModelAndView;
		}
    }
	
	/**
	 * 修改上下架状态
	 */
	@ResponseBody
	@RequestMapping("/updateShowStatus")
	public ReturnData updateShowStatus(Integer id,Integer status){
		int ret = backCourseInfoDao.updateIsShow(id,status);
		if(ret>0){
			return new ReturnData(200,"修改成功");
		}else{
			return new ReturnData(500,"修改失败");
		}
	}
	
}
